/**
 * @file mmc.h
 * @brief head file for mmc.h
 * @details
 *  > * Macro 'MMC_BYTE_ALIGNMENT' define the byte align, you can change it to 1,2,4,8,16,32
 *  > * Macro 'MMC_EXSDRAM_MAX_AS_HEAP_SIZE' define the static array buffer size,
 *      you can change it according your device's resource;
 *  > * In the 'mmc.c' file, you can change the attribute of exSdramHeap[MMC_EXSDRAM_MAX_AS_HEAP_SIZE] 
 *      to redirect the exSdramHeap array's location.
 * @author Qilong Huang(huangqilong@memsensing.com)
 * @date 2022-4-3
 * @version 1.0
 * @copyright Copyright (c) 
 * All rights reserved.
 * *************************************************
 * @par Change log:
 * <table>
 * <tr><th>Date <th>Version  <th>Author <th>Description
 * <tr><td>2018/08/17   <td>1.0 <td>Qilong Huang  <td>Initial
 * </table>
 *
 *********************************************************
 */
#ifndef __MMC_H
#define __MMC_H

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#define MMC_BYTE_ALIGNMENT 8

#ifndef MMC_BYTE_ALIGNMENT
#define MMC_BYTE_ALIGNMENT 8
#endif

#if MMC_BYTE_ALIGNMENT == 32
#define MMC_BYTE_ALIGNMENT_MASK (0x001f)
#elif MMC_BYTE_ALIGNMENT == 16
#define MMC_BYTE_ALIGNMENT_MASK (0x000f)
#elif MMC_BYTE_ALIGNMENT == 8
#define MMC_BYTE_ALIGNMENT_MASK (0x0007)
#elif MMC_BYTE_ALIGNMENT == 4
#define MMC_BYTE_ALIGNMENT_MASK (0x0004)
#elif MMC_BYTE_ALIGNMENT == 2
#define MMC_BYTE_ALIGNMENT_MASK (0x0001)
#elif MMC_BYTE_ALIGNMENT == 1
#define MMC_BYTE_ALIGNMENT_MASK (0x0000)
#endif

#define MMC_EXSDRAM_MAX_AS_HEAP_SIZE 16 * 1024 * 1024

#define MMC_BLOCK_STATUS_EMPTY_FLAG 0x80
#define MMC_BLOCK_STATUS_START_BLOCK_FLAG 0x40
#define MMC_BLOCK_STATUS_END_BLOCK_FLAG 0x20

typedef struct mmcBlock
{
    size_t BlockSize;
    unsigned int BlockStatus;
    struct mmcBlock *NextBlock;
    uint8_t *VaildSpaceStart;
} mmc_Block_t;
void *MMC_Alloc(size_t xRequestSize);
void MMC_Free(void *pFreeAddress);

#ifdef __cplusplus
}
#endif

#endif